package com.ruoyi.printer.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.printer.domain.PrinterOrder;
import com.ruoyi.printer.service.IPrinterOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 订单Controller
 * 
 * @author yanyi
 * @date 2023-07-13
 */
@RestController
@RequestMapping("/printer/order")
public class PrinterOrderController extends BaseController
{
    @Autowired
    private IPrinterOrderService printerOrderService;

    /**
     * 查询订单列表
     */
    @PreAuthorize("@ss.hasPermi('printer:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(PrinterOrder printerOrder)
    {
        startPage();
        List<PrinterOrder> list = printerOrderService.selectPrinterOrderList(printerOrder);
        return getDataTable(list);
    }

    /**
     * 导出订单列表
     */
    @PreAuthorize("@ss.hasPermi('printer:order:export')")
    @Log(title = "订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PrinterOrder printerOrder)
    {
        List<PrinterOrder> list = printerOrderService.selectPrinterOrderList(printerOrder);
        ExcelUtil<PrinterOrder> util = new ExcelUtil<PrinterOrder>(PrinterOrder.class);
        util.exportExcel(response, list, "订单数据");
    }

    /**
     * 获取订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('printer:order:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") String orderId)
    {
        return success(printerOrderService.selectPrinterOrderByOrderId(orderId));
    }

    /**
     * 新增订单
     */
    @PreAuthorize("@ss.hasPermi('printer:order:add')")
    @Log(title = "订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PrinterOrder printerOrder)
    {
        return toAjax(printerOrderService.insertPrinterOrder(printerOrder));
    }

    /**
     * 修改订单
     */
    @PreAuthorize("@ss.hasPermi('printer:order:edit')")
    @Log(title = "订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PrinterOrder printerOrder)
    {
        return toAjax(printerOrderService.updatePrinterOrder(printerOrder));
    }

    /**
     * 删除订单
     */
    @PreAuthorize("@ss.hasPermi('printer:order:remove')")
    @Log(title = "订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable String[] orderIds)
    {
        return toAjax(printerOrderService.deletePrinterOrderByOrderIds(orderIds));
    }
}
